<?php
	// $Id: class.OMBS_Wrapper.php 1200 2003-08-15 07:08:10Z rufustfirefly $
	// $Author: rufustfirefly $
	// Support for the Open Medical Billing System

class OMBS_Wrapper {

	function OMBS_Wrapper ( ) {
		// At this point, do nothing
	} // end constructor OMBS_Wrapper

	function generate ( $_patients ) {
		// If patients isn't an array, make it one
		if (!is_array($_patients)) {
			$patients = array ($_patients);
		} else {
			$patients = $_patients;
		}

		// Generate header
		$buffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
			"<!DOCTYPE OMBS SYSTEM \"http://66.152.215.155/".
				"pub/ombs.dtd\">\n".
			"<!-- Generated by ".PACKAGENAME." v".VERSION." -->\n".
			"<OMBS generated=\"".PACKAGENAME." ".VERSION."\" ".
				"version=\"1.0\">\n";

		// Loop through all patients
		foreach ($patients as $__garbage => $patient) {
			$this_patient = CreateObject('_FreeMED.OMBS_Patient', $patient);
			$buffer .= $this_patient->generate();
			unset($this_patient);
		}

		// Add footer
		$buffer .= "\n</OMBS>\n";

		// Return formed XML
		return $buffer;
	} // end method generate

	function insurance_billing_patients ($facility = 0) {
		$query = "SELECT DISTINCT procpatient AS patient ".
			"FROM procrec ".
				// Must have actual balance to send
			"WHERE procbalcurrent > '0' ".
				// Has to be an insurance billable item
			"AND procbillable = '0' ".
				// Subdivide by POS, if we have that
			( $facility > 0 ?
				"AND procpos = '".addslashes($facility)."'" :
				'' );
		$result = $GLOBALS['sql']->query($query);
		if ($GLOBALS['sql']->results($result)) {
			$return = array ();
			while ($r = $GLOBALS['sql']->fetch_array($result)) {
				$return[] = $r['patient'];
			}
			return $return;
		} else {
			return array ();
		}
	} // end method insurance_billing_patients

} // end class OMBS_Wrapper

?>
